﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CQFQW
{
    /// <summary>
    /// 获取地址
    /// </summary>
   public class GetUrl
    {
       /// <summary>
        /// 存 地址的集合
        /// </summary>
       private IList<string> _strList;
       /// <summary>
       /// 序号
       /// </summary>
       private int _sequence = -1;
       /// <summary>
       /// 是否结束循环
       /// </summary>
       public bool IsEndLoop { get; set; }

       /// <summary>
       /// 日志记录事件
       /// </summary>
       public event LogCallback logEvent;

       public GetUrl(IList<string> strList)
       {
           if (strList==null)
           {
               strList = new List<string>();
           }
           this._strList = strList;
       }

       /// <summary>
       /// 获取地址
       /// </summary>
       /// <returns></returns>
       public string GetAdress()
       {
           lock (this)
           {
               if (++_sequence < this._strList.Count)
               {
                   return this._strList[_sequence];
               }
               else
               {
                   IsEndLoop = true;
                   if (logEvent!=null)
                   {
                       logEvent();
                   }
                   return null;
               }
               
           }
       }
    }
}
